package com.tianlu.store.common;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author liangdl
 * @since 2023/3/8 16:37
 */
public abstract class MyBaseServiceImpl<D extends MyBaseMapper<T>, T extends BaseEntity<T>> extends ServiceImpl<D, T> implements MyBaseService<T> {
    @Autowired
    protected D dao;

    public List<T> findList(T entity) {
        List<T> list = this.dao.findList(entity);
        if (list == null) {
            list = Lists.newArrayList();
        }
        return list;
    }

    public PageResult<T> findPage(T entity) {
        if (entity.getPage() != null && entity.getRows() != null) {
            PageHelper.startPage(entity.getPage(), entity.getRows());
        }

        return PageResult.resultPage(new PageInfo(this.findList(entity)));
    }

}
